﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Data;
using HT.DBUtility;

namespace HT.DAL
{
    public class Dal_YyydaH_1
    {

        #region  Method


        public int GetMaxDjlsh()
        {
            string sql = "select djlsh from yyydaH order by djlsh desc";
            object obj = SQLHelper.GetSingle(sql);

            int djlsh = 0;
            if (obj != null)
            {
                djlsh = int.Parse(obj.ToString());
            }
            djlsh++;

            return djlsh;
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool AddYyydaH(yyydaHModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into yyydaH(");
            strSql.Append("DjLsh, ygbh,ymmc,dmbh,dmmc,Ygxb,Ygjg,xl,Ygbz,djyh,djsj,xgyh,xgsj,mm,qxjb,zdzk,lxdh)");
            strSql.Append(" values (");
            strSql.Append("" + model.DjLsh   + ",'" + model.ygbh + "','" + model.ymmc + "','" + model.dmbh + "','" + model.dmmc + "','" + model.Ygxb + "','" + model.Ygjg + "','" + model.xl + "','" + model.Ygbz + "','" + model.djyh + "','" + model.djsj + "','" + model.xgyh + "','" + model.xgsj + "','" + model.mm + "'," + model.qxjb + "," + model.zdzk + ",'"+model.Lxdh+"')");

            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateYyydaH(yyydaHModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update yyydaH set ");
        //    strSql.Append("DjLsh=" + model.DjLsh + ",");
       
            //   strSql.Append("ygbh='" + model.ygbh + "',");
            strSql.Append("ymmc='" + model.ymmc + "',");
            strSql.Append("dmbh='" + model.dmbh + "',");
            strSql.Append("dmmc='" + model.dmmc + "',");
            strSql.Append("Ygxb='" + model.Ygxb + "',");
            strSql.Append("Ygjg='" + model.Ygjg + "',");
            strSql.Append("xl='" + model.xl + "',");
            strSql.Append("Ygbz='" + model.Ygbz + "',");
            strSql.Append("djyh='" + model.djyh + "',");
            strSql.Append("djsj='" + model.djsj + "',");
            strSql.Append("xgyh='" + model.xgyh + "',");
            strSql.Append("xgsj='" + model.xgsj + "',");
            strSql.Append("mm='" + model.mm + "',");
            strSql.Append("qxjb=" + model.qxjb + ",");
            strSql.Append("zdzk=" + model.zdzk + ",");

            strSql.Append("lxdh='" + model.Lxdh + "'");

            strSql.Append(" where ygbh='" + model.ygbh + "'");


            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteYyydaH(string ygbh)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from yyydaH ");
            strSql.Append(" where ygbh='" + ygbh + "'");


            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 获取数据Model
        /// </summary>
        /// <param name="ygbh"></param>
        /// <returns></returns>
        public yyydaHModel GetYyydaHModel(string ygbh)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,ygbh,ymmc,dmbh,dmmc,Ygxb,Ygjg,xl,Ygbz,djyh,djsj,xgyh,xgsj,mm,qxjb,zdzk from yyydaH ");
            strSql.Append(" where ygbh='" + ygbh + "'");


            yyydaHModel model = new yyydaHModel();
            DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["DjLsh"] != null && dt.Rows[0]["DjLsh"].ToString() != "")
                {
                    model.DjLsh = int.Parse(dt.Rows[0]["DjLsh"].ToString());
                }
                if (dt.Rows[0]["DjBtZdh"] != null && dt.Rows[0]["DjBtZdh"].ToString() != "")
                {
                    model.DjBtZdh = int.Parse(dt.Rows[0]["DjBtZdh"].ToString());
                }
                if (dt.Rows[0]["DjFtZdh"] != null && dt.Rows[0]["DjFtZdh"].ToString() != "")
                {
                    model.DjFtZdh = int.Parse(dt.Rows[0]["DjFtZdh"].ToString());
                }
                if (dt.Rows[0]["DjStZdh"] != null && dt.Rows[0]["DjStZdh"].ToString() != "")
                {
                    model.DjStZdh = int.Parse(dt.Rows[0]["DjStZdh"].ToString());
                }
                if (dt.Rows[0]["DjState"] != null && dt.Rows[0]["DjState"].ToString() != "")
                {
                    model.DjState = dt.Rows[0]["DjState"].ToString();
                }
                if (dt.Rows[0]["DjCount"] != null && dt.Rows[0]["DjCount"].ToString() != "")
                {
                    model.DjCount = int.Parse(dt.Rows[0]["DjCount"].ToString());
                }
                if (dt.Rows[0]["ygbh"] != null && dt.Rows[0]["ygbh"].ToString() != "")
                {
                    model.ygbh = dt.Rows[0]["ygbh"].ToString();
                }
                if (dt.Rows[0]["ymmc"] != null && dt.Rows[0]["ymmc"].ToString() != "")
                {
                    model.ymmc = dt.Rows[0]["ymmc"].ToString();
                }
                if (dt.Rows[0]["dmbh"] != null && dt.Rows[0]["dmbh"].ToString() != "")
                {
                    model.dmbh = dt.Rows[0]["dmbh"].ToString();
                }
                if (dt.Rows[0]["dmmc"] != null && dt.Rows[0]["dmmc"].ToString() != "")
                {
                    model.dmmc = dt.Rows[0]["dmmc"].ToString();
                }
                if (dt.Rows[0]["Ygxb"] != null && dt.Rows[0]["Ygxb"].ToString() != "")
                {
                    model.Ygxb = dt.Rows[0]["Ygxb"].ToString();
                }
                if (dt.Rows[0]["Ygjg"] != null && dt.Rows[0]["Ygjg"].ToString() != "")
                {
                    model.Ygjg = dt.Rows[0]["Ygjg"].ToString();
                }
                if (dt.Rows[0]["xl"] != null && dt.Rows[0]["xl"].ToString() != "")
                {
                    model.xl = dt.Rows[0]["xl"].ToString();
                }
                if (dt.Rows[0]["Ygbz"] != null && dt.Rows[0]["Ygbz"].ToString() != "")
                {
                    model.Ygbz = dt.Rows[0]["Ygbz"].ToString();
                }
                if (dt.Rows[0]["djyh"] != null && dt.Rows[0]["djyh"].ToString() != "")
                {
                    model.djyh = dt.Rows[0]["djyh"].ToString();
                }
                if (dt.Rows[0]["djsj"] != null && dt.Rows[0]["djsj"].ToString() != "")
                {
                    model.djsj = DateTime.Parse(dt.Rows[0]["djsj"].ToString());
                }
                if (dt.Rows[0]["xgyh"] != null && dt.Rows[0]["xgyh"].ToString() != "")
                {
                    model.xgyh = dt.Rows[0]["xgyh"].ToString();
                }
                if (dt.Rows[0]["xgsj"] != null && dt.Rows[0]["xgsj"].ToString() != "")
                {
                    model.xgsj = DateTime.Parse(dt.Rows[0]["xgsj"].ToString());
                }
                if (dt.Rows[0]["mm"] != null && dt.Rows[0]["mm"].ToString() != "")
                {
                    model.mm = dt.Rows[0]["mm"].ToString();
                }
                if (dt.Rows[0]["qxjb"] != null && dt.Rows[0]["qxjb"].ToString() != "")
                {
                    model.qxjb = int.Parse(dt.Rows[0]["qxjb"].ToString());
                }
                if (dt.Rows[0]["zdzk"] != null && dt.Rows[0]["zdzk"].ToString() != "")
                {
                    model.zdzk = decimal.Parse(dt.Rows[0]["zdzk"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }



        #endregion
    }
}
